package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author FengHuan Wang
 * @Date 2025/1/5 12:56
 * @Version 1.0
 */
@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Api(tags = "管理端订单相关接口")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;
    /*管理端订单查询功能*/
    @GetMapping("/conditionSearch")
    @ApiOperation("查询订单接口")
    public Result<PageResult> orderPageQuery(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("管理端开始订单分页查询");
        PageResult result = orderService.adminOrderPageQuery(ordersPageQueryDTO);
        return Result.success(result);
    }

    /*各个状态的订单数量统计*/
    @GetMapping("/statistics")
    @ApiOperation("各个状态的订单数量接口")
    public Result<OrderStatisticsVO> statistic(){
        log.info("开始查询各个状态的订单");
        OrderStatisticsVO orderStatisticsVO = orderService.statistics();
        return Result.success(orderStatisticsVO);
    }

    /*查询订单详细*/
    @GetMapping("/details/{id}")
    @ApiOperation("查询订单详情接口")
    public Result<OrderVO> getOrderDetail(@PathVariable Long id){
        OrderVO orderVO = orderService.queryOrderDetails(id);
        return Result.success(orderVO);
    }


    /*商家接单功能*/
    @PutMapping("/confirm")
    @ApiOperation("商家接单功能接口")
    public Result confirmOrder(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        orderService.orderConfirm(ordersConfirmDTO);
        return Result.success();
    }

    /*商家拒单功能*/
    @PutMapping("/rejection")
    @ApiOperation("商家拒单接口")
    public  Result rejectOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO) throws Exception {
        log.info("商家拒单");
        orderService.rejectOrder(ordersRejectionDTO);
        return Result.success();
    }

    /*派送订单功能*/
    @PutMapping("/delivery/{id}")
    @ApiOperation("订单派送接口")
    public Result deliveryOrder(@PathVariable Long id){
        orderService.delivery(id);
        return Result.success();
    }

    /*完成订单功能*/
    @PutMapping("complete/{id}")
    @ApiOperation("完成订单接口")
    public Result complete(@PathVariable Long id){
        log.info("完成订单");
        orderService.complete(id);
        return  Result.success();
    }

    /**
     * 取消订单
     *
     * @return
     */
    @PutMapping("/cancel")
    @ApiOperation("取消订单")
    public Result cancel(@RequestBody OrdersCancelDTO ordersCancelDTO) throws Exception {
        orderService.cancel(ordersCancelDTO);
        return Result.success();
    }
}
